package com.zdoon.controller;

import com.zdoon.pojo.Emp;
import com.zdoon.pojo.EmpQueryParam;
import com.zdoon.pojo.PageResult;
import com.zdoon.pojo.Result;
import com.zdoon.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

//    分页查询员工列表
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        log.info("分页查询员工列表，参数：{}", empQueryParam);
         PageResult<Emp> empPageResult = empService.page(empQueryParam);
        return Result.success(empPageResult);
    }

//    添加员工
    @PostMapping
    public Result add(@RequestBody Emp emp){
        log.info("添加员工，参数：{}", emp);
        empService.add(emp);
        return Result.success();
    }

//    删除员工
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工，参数：{}", ids);
        empService.delete(ids);
        return Result.success();
    }

//    根据id查询员工及其工作经历

    @GetMapping("{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工及其工作经历，参数：{}", id);
        Emp emp = empService.getInfo(id);
        return Result.success(emp);
    }


//    修改员工
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工，参数：{}", emp);
        empService.update(emp);
        return Result.success();
    }


    @GetMapping("/list")
    public Result list(){
        log.info("查询所有员工");
        List<Emp> empList = empService.list();
        return Result.success(empList);
    }












}
